const express = require('express')

const app = express()

// 引入包
let bodyParser = require('body-parser');

app.get('/serverGet',(request,response)=>{
    console.log(request)
    console.log(request.query)
    console.log(request.query.name)
    response.setHeader('Access-Control-Allow-Origin', '*')
    response.send("原生Ajax,你好啊，我是"+request.query.name+"今年"+request.query.age)
})


//配置body-parser
// 只要加上这个配置，则在req请求对象上会多出来一个属性：body
// 因此可以直接通过req.body来获取表单post请求体数据
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());


app.post('/serverPost',(request,response)=>{
    console.log(request)
    response.setHeader('Access-Control-Allow-Origin', '*')
    response.send("原生AjaxPost,你好啊,我是"+request.body.name+"我很"+request.body.status)
})

app.listen('8000',()=>{
    console.log('serverGet 启动')
})